/**
 * 系统管理--我的租车信息
 */
var rent = {
    id: "rentTable", //表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    condition: {
    }
};
/**
 * 初始化表格的列
 */
rent.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {
            title: '序号', field: 'number', width: 1, align: 'center', valign: 'middle', formatter: function (value, row, index) {
                return index + 1;
            }
        },
        {title: '姓名', field: 'cardName', align: 'center', valign: 'middle', sortable: true},
        {title: '车辆类型', field: 'carType', align: 'center', valign: 'middle', sortable: true},
        {title: '租赁时间', field: 'rentTime', align: 'center', valign: 'middle', sortable: true},
        {title: '押金', field: 'rentDeposit', align: 'center', valign: 'middle', sortable: true},
        {title: '总消费', field: 'rentMoney', align: 'center', valign: 'middle', sortable: true},
        {title: '租车地点', field: 'rentPlace', align: 'center', valign: 'middle', sortable: true},
        {title: '还车地点', field: 'returnPlace', align: 'center', valign: 'middle', sortable: true},
        {title: '操作', field: 'isReturn', sortable: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {
            if (row.isReturn === 0) {
                return '<button type="button" class="btn btn-xs btn-success" onclick="rent.returnCar()">还车</button>'
            }
            return '<button type="button" class="btn btn-xs btn-success" readonly="">已还车</button>'
        }},
        {title: '评价', field: 'recordId', align: 'center', valign: 'middle', sortable: true, formatter:function (value, row, index) {
                return '<button type="button" class="btn btn-xs btn-danger" onclick="rent.assessCar(\''+row.recordId+'\')">评价</button>'
        }}
    ];
};

/**
 * 点击还车
 */
rent.returnCar = function () {
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/car/return", function () {
            Feng.success("还车成功!");
            rent.table.refresh();
        }, function (data) {
            Feng.error("还车失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    };
    Feng.confirm("是否还车?", operation);
};

/**
 * 点击评价
 */
rent.assessCar = function(recordId){
    var selectId = recordId;
    if (!recordId) {
        selectId = this.seItem.activityId;
    }
    this.layerIndex = layer.open({
        type: 2,
        title: '评价',
        area: ['300px', '580px'],
        fix: false,
        maxmin: true,
        content: Feng.ctxPath + '/car/car_assess?recordId=' + selectId
    });
};


/**
 * 点击导出excel
 */
/*rent.getMyRentEls = function () {
    this.layerIndex = layer.open({
        type: 2,
        title: '站内搜索',
        area: ['800px', '650px'],
        fix: false,
        maxmin: true,
        content: "https://www.baidu.com/s?wd=奔驰"
    });

};*/




/**
 * 点击买断按钮
 */
rent.buy = function () {
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/car/buy", function () {
            Feng.success("购买成功!");
            parent.location.reload();
        }, function (data) {
            Feng.error("购买失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    };
    Feng.confirm("确认购买?", operation);
};

$(function () {
    rent.app = new Vue({
        el: '#carManagerPage',
        data: rent.condition
    });
    var defaultColunms = rent.initColumn();
    var table = new BSTable("rentTable", "/car/rentList", defaultColunms);
    table.setPaginationType("client");
    rent.table = table.init();
    laydate.render({
        elem: '#timeLimit',
        range: true,
        theme: '#009efb',
        max: Feng.currentDate()
    });
});